package com.danciyixue.boot.dcyx.controller;

import com.danciyixue.boot.dcyx.service.UserExtensionsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.danciyixue.boot.dcyx.model.form.UserExtensionsForm;
import com.danciyixue.boot.dcyx.model.query.UserExtensionsQuery;
import com.danciyixue.boot.dcyx.model.vo.UserExtensionsVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.danciyixue.boot.common.result.PageResult;
import com.danciyixue.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 用户扩展配置信息前端控制层
 *
 * @author youlaitech
 * @since 2025-06-15 16:36
 */
@Tag(name = "用户扩展配置信息接口")
@RestController
@RequestMapping("/api/v1/user-extensions")
@RequiredArgsConstructor
public class UserExtensionsController  {

    private final UserExtensionsService userExtensionsService;

    @Operation(summary = "用户扩展配置信息分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('dcyx:user-extensions:query')")
    public PageResult<UserExtensionsVO> getUserExtensionsPage(UserExtensionsQuery queryParams ) {
        IPage<UserExtensionsVO> result = userExtensionsService.getUserExtensionsPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增用户扩展配置信息")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('dcyx:user-extensions:add')")
    public Result<Void> saveUserExtensions(@RequestBody @Valid UserExtensionsForm formData ) {
        boolean result = userExtensionsService.saveUserExtensions(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取用户扩展配置信息表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('dcyx:user-extensions:edit')")
    public Result<UserExtensionsForm> getUserExtensionsForm(
        @Parameter(description = "用户扩展配置信息ID") @PathVariable Long id
    ) {
        UserExtensionsForm formData = userExtensionsService.getUserExtensionsFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改用户扩展配置信息")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('dcyx:user-extensions:edit')")
    public Result<Void> updateUserExtensions(
            @Parameter(description = "用户扩展配置信息ID") @PathVariable Long id,
            @RequestBody @Validated UserExtensionsForm formData
    ) {
        boolean result = userExtensionsService.updateUserExtensions(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除用户扩展配置信息")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('dcyx:user-extensions:delete')")
    public Result<Void> deleteUserExtensionss(
        @Parameter(description = "用户扩展配置信息ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = userExtensionsService.deleteUserExtensionss(ids);
        return Result.judge(result);
    }
}
